{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "BchPeds"

// By ArtemQa146

// 20@ ped - 10@ render
// 21@ ped - 11@ render
// 22@ ped - 12@ render
// 23@ ped - 13@ render
// 24@ ped - 14@ render

const
    Peds_Find = 19@
    Ped_Skin = 1@
    Ped_Select = 17@
    Bit_sets = 31@
    Select_Hand = 1
    Number_Peds = 6
    iBuffer = 28@
    Pause_Time = 300
    Minus_Pause = 200
    Pause = 1000
end

0085: iBuffer = 0@ // (int)
0@ = -1

while true
wait 100
if
    Player.Defined($PLAYER_CHAR)
then
gosub @Ped_20
gosub @Realese_animation
    if
        not $ACTIVE_INTERIOR == 0
    then
        gosub @References_remove
        continue
    end

0E40: get_current_hour 2@
0D59: get_current_weather_to 1@
if and
    2@ >= 5
    2@ < 23
    not 1@ == 8 // not weather rain
    not 1@ == 16 // not weather rain 2
then
    if or
        856D: not actor 20@ defined
        856D: not actor 21@ defined
        856D: not actor 22@ defined
        856D: not actor 23@ defined
        856D: not actor 24@ defined
        856D: not actor 25@ defined
    then
    Peds_Find = 0
    while 0EA7: get_any_char_no_save_recursive Peds_Find progress_to Peds_Find char_to 0@
    4@ = 50.0
    if 82CB:   not actor 0@ bounding_sphere_visible
    then 4@ = 20.0
    end
        080E: get_actor 0@ ped_event_to 1@
        if and
            not 1@ == 9 // ped damaged
            80DF: not actor 0@ driving
            not is_char_script_controlled 0@
            not locate_char_distance_to_char 0@ char $PLAYER_ACTOR radius 4@
            locate_char_distance_to_char 0@ char $PLAYER_ACTOR radius 90.0
        then
            0470: 3@ = actor 0@ current_weapon
            0EFF: get_char_simplest_active_task 0@ id_to 1@ pointer_to 2@
            if and
                3@ == 0 //unarmed
                1@ == 900 //walk
                not Actor.Animation(0@) == "sprint_panic"
                not Actor.Animation(0@) == "woman_runpanic"
                not Actor.Animation(0@) == "idle_chat"
            then
                gosub @Ped_skin
                if
                    Ped_Skin == true
                then
                    gosub @Load_animation
                    if
                        056D: actor 0@ defined
                    then
                        if
                            not is_char_script_controlled 0@
                        then

                            for Ped_Select = 0 to Number_Peds step 1
                                if
                                    856D: not actor 20@(Ped_Select,1i) defined
                                then

                                    if or
                                        Ped_Select == 0 // 
                                        Ped_Select == 1 // 
                                        Ped_Select == 2 // 
                                    then
                                        0085: 20@(Ped_Select,1i) = 0@ // (int)
                                        0E0B: mark_char_as_needed 20@(Ped_Select,1i)

                                        // ,   
                                        3@ = 24

                                        gosub @Beach
                                        gosub @Ped_beach
                                        wait Pause
                                        break
                                    end

                                    if
                                        Ped_Select == 3 //  
                                    then
                                        0085: 20@(Ped_Select,1i) = 0@ // (int)
                                        0E0B: mark_char_as_needed 20@(Ped_Select,1i)

                                        gosub @Ball
                                        gosub @Ped_Ball
                                        wait Pause
                                        break
                                    end

                                    if
                                        Ped_Select == 4 // 
                                    then
                                        0085: 20@(Ped_Select,1i) = 0@ // (int)
                                        0E0B: mark_char_as_needed 20@(Ped_Select,1i)
                                        0209: 2@ = random_int_in_ranges 1 3 // random hand
                                        if 2@ == 1
                                        then 08BD: set Bit_sets bit Select_Hand
                                        else 08C3: clear Bit_sets bit Select_Hand
                                        end

                                        29@ = 0
                                        gosub @drink
                                        if 2@ < 6
                                        then gosub @Ped_drink
                                        else gosub @Ped_drink_standart
                                        end
                                        wait Pause
                                        break
                                    end

                                    if
                                        Ped_Select == 5 //  
                                    then
                                        0085: 20@(Ped_Select,1i) = 0@ // (int)
                                        0E0B: mark_char_as_needed 20@(Ped_Select,1i)
                                        gosub @Plank
                                        gosub @Ped_Plank
                                        wait Pause
                                        break
                                    end
                                end
                            end
                            break
                        end
                    end
                end
            end
        end
    end
end
end
end
end

//  ,   

:BEach
089F: get_actor 0@ pedtype_to 2@
if 2@ == 4 //man
then 0209: 2@ = random_int_in_ranges 3 10
else 0209: 2@ = random_int_in_ranges 3 16
end
2@ += 69
2@ *= 4
read_struct_offset 1@ iBuffer offset 2@ size 4   // Read ID of Model 2
return

:Ball
4@ = 0.12
5@ = 0.2
6@ = 0.0
7@ = 0.0
9@ = 0.0
0209: 2@ = random_int_in_ranges 1 3
if
    2@ == 1
then
    2@ = 69
    2@ *= 4
    read_struct_offset 1@ iBuffer offset 2@ size 4   // Read ID of Model 2
end
if
    2@ == 2
then
    2@ = 59
    2@ *= 4
    read_struct_offset 1@ iBuffer offset 2@ size 4   // Read ID of Model 2
end
return

:drink
0209: 2@ = random_int_in_ranges 1 11
if
    2@ < 6
then
    2@ += 39
    2@ *= 4
    read_struct_offset 1@ iBuffer offset 2@ size 4   // Read ID of Model 2
    2@ = 1
end
4@ = 0.09
5@ = 0.025
6@ = -0.02
7@ = 180.0
8@ = 0.9
if
    2@ == 6
then
    1@ = 1455
end
if
    2@ == 7
then
    1@ = 2647
    8@ = 0.5
end
if
    2@ == 8
then
    1@ = 1486
    8@ = 0.8
end
if
    2@ == 9
then
    1@ = 2601
    8@ = 0.8
end
if
    2@ == 10
then
    1@ = 1546
    4@ = 0.08
    8@ = 0.8
end
return

:Plank
0209: 2@ = random_int_in_ranges 1 3
if 2@ == 1
then 
    2@ += 69
    2@ *= 4
    read_struct_offset 1@ iBuffer offset 2@ size 4   // Read ID of Model 2
end
if 2@ == 2
then
    2@ += 69
    2@ *= 4
    read_struct_offset 1@ iBuffer offset 2@ size 4   // Read ID of Model 2
end
return

//  

:Ped_beach
0F02:  20@(Ped_Select,1i) special_model 1@ bone 3@ offset 0 0 0 rotation 0 0 0 scale 10@(Ped_Select,1i) // bone 34 left hand, 24 right hand, 9 had, 3 tors
0E30: set_render_object_auto_hide 10@(Ped_Select,1i) dead 1 weapon 1 car 1
return

:Ped_Ball
0F02:  20@(Ped_Select,1i) special_model 1@ bone 24 offset 4@ 5@ 6@ rotation 0 7@ 9@ scale 10@(Ped_Select,1i) // bone 34 left hand, 24 right hand, 9 had, 3 tors
0E30: set_render_object_auto_hide 10@(Ped_Select,1i) dead 1 weapon 1 car 1
0A1A: actor 20@(Ped_Select,1i) perform_walk_animation "walk1Alter" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 -1 ms // versionC
return

:Ped_drink
if
    08B7:   test Bit_sets bit Select_Hand
then
    7@ = 0.0
    2@ = 24
else
    2@ = 34
end
0F02:  20@(Ped_Select,1i) special_model 1@ bone 2@ offset 4@ 5@ 6@ rotation 0 7@ 0 scale 10@(Ped_Select,1i) // bone 34 left hand, 24 right hand, 9 had, 3 tors
set_render_object_scale 10@(Ped_Select,1i) 8@ 8@ 8@
0E30: set_render_object_auto_hide 10@(Ped_Select,1i) dead 1 weapon 1 car 1
0006: TIMERA = 0
return

:Ped_drink_standart
model.Load(1@)
if
    not model.Available(1@)
then
    repeat
    wait 0
    model.Load(1@)
    until model.Available(1@)
end
038B: load_requested_models
if
    08B7:   test Bit_sets bit Select_Hand
then
    7@ = 0.0
    2@ = 24
else
    2@ = 34
end
if
    056D:   actor 20@(Ped_Select,1i) defined
then
    0E2E: create_render_object_to_char_bone 20@(Ped_Select,1i) model 1@ bone 2@ offset 4@ 5@ 6@ rotation 0 7@ 0 store_to 10@(Ped_Select,1i)
    set_render_object_scale 10@(Ped_Select,1i) 8@ 8@ 8@
    0E30: set_render_object_auto_hide 10@(Ped_Select,1i) dead 1 weapon 1 car 1
    0006: TIMERA = 0
end
model.Destroy(1@)
return

:PEd_Plank
0F02:  20@(Ped_Select,1i) special_model 1@ bone 34 offset 0.01 0.035 0 rotation 0 180.0 180.0 scale 10@(Ped_Select,1i) // bone 34 left hand, 24 right hand, 9 had, 3 tors
0E30: set_render_object_auto_hide 10@(Ped_Select,1i) dead 1 weapon 1 car 1
0A1A: actor 20@(Ped_Select,1i) perform_walk_animation "WorkPlank" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 1 -1 ms // versionC
return

//   


:Ped_20
for Ped_Select = 0 to Number_Peds step 1
wait 10
    if
        056D: actor 20@(Ped_Select,1i) defined
    then
        0A96: 3@ = ped 20@(Ped_Select,1i) struct
        0D4E: 2@ = read_struct 3@ offset 0x470 size 1
        if 08B7:   test 2@ bit 3 //      
        then
            08C3: clear 2@ bit 3
            0E28: write_struct 3@ offset 0x470 size 1 value 2@ //      
            10@(Ped_Select,1i) = -1
            gosub @PedsMod_Delete_Render
            continue
        end
        if and
            not actor.Dead(20@(Ped_Select,1i))
            is_char_script_controlled 20@(Ped_Select,1i)
            locate_char_distance_to_char 20@(Ped_Select,1i) char $PLAYER_ACTOR radius 120.0
        then
        
            // 
            if
                Ped_Select == 3
            then
            
                0EFF: get_char_simplest_active_task 20@(Ped_Select,1i) id_to 3@ pointer_to 2@
                if and
                    timerb > 5000
                    not 3@ == 401
                    3@ == 900
                    not Actor.Animation(20@(Ped_Select,1i)) == "walk1Alter"
                    02CB:   actor 20@(Ped_Select,1i) bounding_sphere_visible
                then
                    0A1A: actor 20@(Ped_Select,1i) perform_walk_animation "walk1Alter" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 -1 ms // versionC
                    timerb = 0
                end
            end
            
            // 
            if
                Ped_Select == 4
            then
                0EFF: get_char_simplest_active_task 20@(Ped_Select,1i) id_to 3@ pointer_to 2@
                if and
                    02CB:   actor 20@(Ped_Select,1i) bounding_sphere_visible
                    3@ == 900
                    0019:   TIMERA > 15000
                then
                    if
                        08B7:   test Bit_sets bit Select_Hand
                    then
                        0A1A: actor 20@(Ped_Select,1i) perform_walk_animation "DRNKBR_PRTL" IFP "GANGS" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 -1 ms // versionC
                        0006: TIMERA = 0
                        29@ += 1
                    else
                        0A1A: actor 20@(Ped_Select,1i) perform_walk_animation "vend_drink2_p" IFP "vending" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 -1 ms // versionC
                        0006: TIMERA = 0
                        29@ += 1
                    end
                end
                if and
                    timerb > 3000
                    29@ >= 5
                then
                    gosub @PedsMod_Delete_Render
                    continue
                end
            end
            
            // 
            if
                Ped_Select == 5
            then
                0EFF: get_char_simplest_active_task 20@(Ped_Select,1i) id_to 3@ pointer_to 2@
                if and
                    timerb > 5000
                    not 3@ == 401
                    3@ == 900
                    not Actor.Animation(20@(Ped_Select,1i)) == "WorkPlank"
                    02CB:   actor 20@(Ped_Select,1i) bounding_sphere_visible
                then
                    0A1A: actor 20@(Ped_Select,1i) perform_walk_animation "WorkPlank" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 -1 ms // versionC
                    timerb = 0
                end
            end

            080E: get_actor 20@(Ped_Select,1i) ped_event_to 1@
            if or
                1@ == 49 // shoot close ped
                0E47: is_char_fighting 20@(Ped_Select,1i)
                actor.Driving(20@(Ped_Select,1i))
                82D8:   not actor 20@(Ped_Select,1i) current_weapon == 0
            then
                gosub @PedsMod_Delete_Render
            end
        else
            gosub @PedsMod_Delete_Render
        end
    end
end
return


//      
:PedsMod_Delete_Render
if
    056D: actor 20@(Ped_Select,1i) defined
then
    if
        not locate_char_distance_to_char 20@(Ped_Select,1i) char $PLAYER_ACTOR radius 50.0
    then
        if
            0E0A: is_char_script_controlled 20@(Ped_Select,1i)
        then
            01C2: remove_references_to_actor 20@(Ped_Select,1i) // Like turning an actor into a random pedestrian
        end
    else
        if
            0E0A: is_char_script_controlled 20@(Ped_Select,1i)
        then
            if
                not 10@(Ped_Select,1i) <= -1
            then
                0E31: set_render_object_visible 10@(Ped_Select,1i) 0
            end
            if
                not actor.Dead(20@(Ped_Select,1i))
            then
                if
                    Ped_Select == 4
                then
                    0E97: clear_char_secondary_tasks 20@(Ped_Select,1i)
                end
            end
            01C2: remove_references_to_actor 20@(Ped_Select,1i) // Like turning an actor into a random pedestrian
        end
    end
end
10@(Ped_Select,1i) = -1
20@(Ped_Select,1i) = -1
return

//  
:Load_animation
if or
    84EE: not animation "PedEventsMod" loaded
    84EE: not animation "VENDING" loaded
    84EE: not animation "GANGS" loaded
then
    repeat
    wait 0
    04ED: load_animation  "PedEventsMod"
    04ED: load_animation  "VENDING"
    04ED: load_animation  "GANGS"
        if and
            04EE: animation "PedEventsMod" loaded
            04EE: animation "VENDING" loaded
            04EE: animation "GANGS" loaded
        then
            break
        end
    until not player.Defined(0)
end
return


:Ped_skin
Ped_skin = false
if or
    02F2:   actor 0@ model == 18 // beach visitor
    02F2:   actor 0@ model == 45 // beach visitor
    02F2:   actor 0@ model == 138 // beach visitor
    02F2:   actor 0@ model == 139  // beach visitor
    02F2:   actor 0@ model == 140 // beach visitor
    02F2:   actor 0@ model == 154 // beach visitor
then
    Ped_skin = true
end
return


//     
:References_remove
for Ped_Select = 0 to Number_Peds step 1
    if
        056D:   actor 20@(Ped_Select,1i) defined
    then
        01C2: remove_references_to_actor 20@(Ped_Select,1i) // Like turning an actor into a random pedestrian
        20@(Ped_Select,1i) = -1
        10@(Ped_Select,1i) = -1
    end
end
return

//      ,   
:Realese_animation
if and
    856D: not actor 20@ defined
    856D: not actor 21@ defined
    856D: not actor 22@ defined
    856D: not actor 23@ defined
    856D: not actor 24@ defined
then
    if and
        04EE: animation "PedEventsMod" loaded
        04EE: animation "VENDING" loaded
        04EE: animation "GANGS" loaded
    then
        04EF: release_animation "PedEventsMod"
        04EF: release_animation "GANGS"
        04EF: release_animation "VENDING"
    end
    0E40: get_current_hour 2@
    0D59: get_current_weather_to 1@
    if or
        2@ < 5
        2@ > 23
        1@ == 8 // not weather rain
        1@ == 16 // not weather rain 2
        not $ACTIVE_INTERIOR == 0
    then
        0A93: terminate_this_custom_script
    end
    if and
        8154:   not actor $PLAYER_ACTOR in_zone 'SMB'
        8154:   not actor $PLAYER_ACTOR in_zone 'VERO'
        8154:   not actor $PLAYER_ACTOR in_zone 'PLS'
        8154:   not actor $PLAYER_ACTOR in_zone 'OCEAF'
    then
        0A93: terminate_this_custom_script
    end
end
return
